﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
namespace PMS
{
    public class JsonHelper
    {
        /// <summary>
        /// 将对象直接转化成Json
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string toJson(object obj)
        {
            return JsonConvert.SerializeObject(obj);
        }
        public static string toPageJson(object list, int count)
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("total", count);
            dic.Add("rows", list);
            return JsonConvert.SerializeObject(dic);
        }
        public static string toPageJsonFooter(object list, int count, object Footer)
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("total", count);
            dic.Add("rows", list);
            dic.Add("footer", Footer);
            return JsonConvert.SerializeObject(dic);
        }
        public static string toDefaultMsg(bool state, params string[]  param)
        {
            Message msg = new Message();
            if (state)
            {
                msg.state = "success";
                msg.msg = "操作成功";
            }
            else
            {
                msg.state = "error";
                msg.msg = "操作失败";
            }
            if (param.Length>0)
            {
                msg.msg = param[0].ToString();
            }
            return JsonConvert.SerializeObject(msg);
        }
    }
}